package com.zq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zq.mapper.UserMapper;
import com.zq.entity.User;
import com.zq.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @description:
 * @author: ZQ
 * @date:   2021-02-25-13:49
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public boolean loginByUser(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("user_name",user.getUserName());
        queryWrapper.eq("user_password",user.getUserPassword());
        User selectOne = userMapper.selectOne(queryWrapper);
        return null != selectOne;
    }
}
